package com.qiwx.pigeon.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.annotation.Nullable;

import com.qiwx.pigeon.R;
import com.qiwx.pigeon.data.CageStatusConfig;
import com.qiwx.pigeon.data.params.CLZTParam;
import com.qiwx.pigeon.data.vo.CageRepairBean;

import java.security.acl.Group;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @description
 * @Author qiwx
 * @Date 2020-06-10 17:34
 * 存栏状态
 **/
public class CageStatusOptionView extends LinearLayout {


    @BindView(R.id.rb_cage_status_sm)
    RadioButton rbCageStatusSm;
    @BindView(R.id.rb_cage_status_sg)
    RadioButton rbCageStatusSg;
    @BindView(R.id.rb_cage_status_ygym)
    RadioButton rbCageStatusYgym;
    @BindView(R.id.rb_cage_status_dz)
    RadioButton rbCageStatusDz;
    @BindView(R.id.rb_cage_status_dg)
    RadioButton rbCageStatusDg;
    @BindView(R.id.rb_cage_status_dm)
    RadioButton rbCageStatusDm;
    @BindView(R.id.rb_cage_status_kl)
    RadioButton rbCageStatusKl;
    @BindView(R.id.group_cage_status_options)
    RadioGroup groupCageStatusOptions;
    @BindView(R.id.rb_cage_status_death_wu)
    RadioButton rbCageStatusDeathWu;
    @BindView(R.id.rb_cage_status_death_1)
    RadioButton rbCageStatusDeath1;
    @BindView(R.id.rb_cage_status_death_2)
    RadioButton rbCageStatusDeath2;
    @BindView(R.id.group_cage_status_death_options)
    RadioGroup groupCageStatusDeathOptions;
    @BindView(R.id.lin_cage_status_options)
    LinearLayout linCageStatusOptions;

    public CageStatusOptionView(Context context) {
        this(context, null);
    }

    public CageStatusOptionView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public CageStatusOptionView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
        initEvent();
        rbCageStatusDeathWu.setChecked(true);
    }

    private void initView(Context context) {
        LayoutInflater mInflater = LayoutInflater.from(context);
        View view = mInflater.inflate(R.layout.cage_status_option, null);
        ButterKnife.bind(this, view);
        addView(view);

    }

    private void initEvent() {
        rbCageStatusDeathWu.setOnCheckedChangeListener((bt, ischeck) -> {
            if (ischeck) {

                rbCageStatusKl.setChecked(true);
                rbCageStatusKl.setVisibility(View.VISIBLE);
                rbCageStatusSm.setVisibility(View.GONE);
                rbCageStatusSg.setVisibility(View.GONE);
                rbCageStatusYgym.setVisibility(View.GONE);
                rbCageStatusDz.setVisibility(View.GONE);
                rbCageStatusDm.setVisibility(View.GONE);
                rbCageStatusDg.setVisibility(View.GONE);
            }
        });
        rbCageStatusDeath1.setOnCheckedChangeListener((bt, ischeck) -> {
            if (ischeck) {
                rbCageStatusDz.setChecked(true);
                rbCageStatusKl.setVisibility(View.GONE);
                rbCageStatusSm.setVisibility(View.GONE);
                rbCageStatusSg.setVisibility(View.GONE);
                rbCageStatusYgym.setVisibility(View.GONE);
                rbCageStatusDz.setVisibility(View.VISIBLE);
                rbCageStatusDm.setVisibility(View.VISIBLE);
                rbCageStatusDg.setVisibility(View.VISIBLE);
            }
        });
        rbCageStatusDeath2.setOnCheckedChangeListener((bt, ischeck) -> {
            if (ischeck) {
                rbCageStatusSm.setChecked(true);
                rbCageStatusKl.setVisibility(View.GONE);
                rbCageStatusSm.setVisibility(View.VISIBLE);
                rbCageStatusSg.setVisibility(View.VISIBLE);
                rbCageStatusYgym.setVisibility(View.VISIBLE);
                rbCageStatusDz.setVisibility(View.GONE);
                rbCageStatusDm.setVisibility(View.GONE);
                rbCageStatusDg.setVisibility(View.GONE);
            }
        });

    }
    //获取存栏状态status
    public int getCageStatus() {
        if (rbCageStatusKl.isChecked()) {
            return CageStatusConfig.STATUS_KL;
        } else if (rbCageStatusDz.isChecked()) {
            return CageStatusConfig.STATUS_DZ;
        } else if (rbCageStatusSg.isChecked()) {
            return CageStatusConfig.STATUS_SG;
        } else if (rbCageStatusSm.isChecked()) {
            return CageStatusConfig.STATUS_SM;
        } else if (rbCageStatusYgym.isChecked()) {
            return CageStatusConfig.STATUS_YGYM;
        } else if (rbCageStatusDg.isChecked()) {
            return CageStatusConfig.STATUS_DG;
        } else if (rbCageStatusDm.isChecked()) {
            return CageStatusConfig.STATUS_DM;
        }
        return CageStatusConfig.STATUS_YGYM;
    }
    public int getCLZGDeathAmount() {
        if (rbCageStatusDeathWu.isChecked()) {
            return 2;
        } else if (rbCageStatusDeath1.isChecked()) {
            return 1;
        } else {
            return 0;
        }
    }


    public CLZTParam getParam() {
        CLZTParam param=new CLZTParam();
        int status = getCageStatus();
        param.setStatus(status);
        param.setAmount(getCLZGDeathAmount());
        param.setType(1);
        return param;

    }


    //重置选项
    public void resetOptions() {
        rbCageStatusDeathWu.setChecked(true);

    }
}
